package ee.ts022.tuum.services.ws.utils;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.xml.datatype.XMLGregorianCalendar;

import ee.ts022.tuum.domain.CstAddress;
import ee.ts022.tuum.domain.Customer;


public class SoapDomainParser {
	private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

	public static Date paresDate(XMLGregorianCalendar calendar) throws ParseException {
		if(calendar == null) {return null;}
		simpleDateFormat.setLenient(false);
		Date result = new Date( simpleDateFormat.parse(calendar.toString()).getTime());
		
		return result;
	}

	public static CstAddress parseCstAddress(ee.ts022.tuum.services.ws.generated.CstAddress cstAddress) {
		if(cstAddress == null) {return null;}
		CstAddress result = new CstAddress();
		result.setCstAddress(cstAddress.getCstAddress());
		Customer c = new Customer();
		c.setCustomer(cstAddress.getCustomer());
		result.setCustomer(c);
		result.setAddress(cstAddress.getAddress());
		result.setAddressType(cstAddress.getAddressType());
		result.setCountry(cstAddress.getCountry());
		result.setHouse(cstAddress.getHouse());
		result.setTownCounty(cstAddress.getTownCounty());
		result.setZip(cstAddress.getZip());
		
		return result;
	}

}
